package com.shanyutiwen.springbootblogtest.response;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class AjaxResponse {
    private boolean isOk;
    private int code;
    private String message;
    private Map<String, Object> data;


    public AjaxResponse(){}

    public static AjaxResponse success() {
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.setOk(true);
        ajaxResponse.setCode(200);
        ajaxResponse.setMessage("请求相应成功！");
        return ajaxResponse;
    }

    @org.jetbrains.annotations.NotNull
    public static AjaxResponse success(Object object) {
        Map<String, Object> map = new HashMap<>();
        map.put("list", object);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.setOk(true);
        ajaxResponse.setCode(200);
        ajaxResponse.setMessage("请求相应成功！");
        ajaxResponse.setData(map);
        return ajaxResponse;
    }

    public static AjaxResponse success(Object object, String message) {
        Map<String, Object> map = new HashMap<>();
        map.put("list", object);

        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.setOk(true);
        ajaxResponse.setCode(200);
        ajaxResponse.setMessage(message);
        ajaxResponse.setData(map);
        return ajaxResponse;
    }
}
